package com.common.action;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import com.common.model.User;
import com.common.service.UserService;

public class UserAction extends BaseAction {
	private UserService userservice;
	private User user;
	private String message;
	private String password;
	private String username;
	private int id;
	private String name;
	private List<User> lst = new ArrayList<User>();
	private String list;
	private String jsonString;
	private String jibie;
	private String feiyong;
	private boolean flag;
	
	//普通用户注册
	public String breg() {
		if (user!= null){
			//查找用户名是否存在
			lst = userservice.list0(user.getUsername());
			if (lst.size()>0){
				message = "账号已存在";
				return "register";
			}else{
				userservice.reg(user);
				 return SUCCESS;
			} 
		}else {
			message = "账号已存在";
			return null;
		}
		
	}
	
	
	public String wadd() {
		return SUCCESS;
	}
	
	public String badd() {	
		return SUCCESS;
	}
	
	public String wsave() {
		
		 userservice.reg(user);
		
		return SUCCESS;
		
	}
	public String bsave() {
		
		 userservice.reg(user);
		
		return SUCCESS;
		
	}
	
	public String list_baoxiu() {
		lst =userservice.list_baoxiu();
		return SUCCESS;
		
	}
	

	public String list_weixiu() {
		lst =userservice.list_weixiu();
		return SUCCESS;
		
	}
	
	public String listPay(){
		lst =userservice.list_weixiu();
		list = lst.toString();
		return SUCCESS;
	}
	
	//根据普通用户姓名进行模糊查询
	public String list(){
		if(user == null){
			lst = userservice.search(null);
		}else{
			lst = userservice.search(user.getName());
		}
		return SUCCESS;
	}
	
	public String wdelete() {	
		userservice.wDel(user);
		return SUCCESS;
	}
	
	public String bdelete() {	
		userservice.bDel(user);
		return SUCCESS;
	}

	public String bupdatepwd(){
		user= userservice.load(id);
		return SUCCESS;
	}
	
	public String bupdate(){
		userservice.bupdate(user);
		return SUCCESS;
	}

	public String add(){
		user= userservice.load(id);
		return SUCCESS;
	}
	
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public UserService getUserservice() {
		return userservice;
	}

	public void setUserservice(UserService userservice) {
		this.userservice = userservice;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getJsonString() {
		return jsonString;
	}

	public void setJsonString(String jsonString) {
		this.jsonString = jsonString;
	}

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<User> getLst() {
		return lst;
	}

	public void setLst(List<User> lst) {
		this.lst = lst;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	

	


	public String getJibie() {
		return jibie;
	}


	public void setJibie(String jibie) {
		this.jibie = jibie;
	}


	public String getFeiyong() {
		return feiyong;
	}


	public void setFeiyong(String feiyong) {
		this.feiyong = feiyong;
	}


	public String login() {

		user = userservice.login(user.getUsername(), user.getPassword());

		JSONObject jo = JSONObject.fromObject(user);

		jsonString = jo.toString();

		return SUCCESS;

	}

	public String reg() {

		flag = userservice.reg(user);

		if (flag) {
			jsonString = "1";
		} else {
			jsonString = "0";
		}

		return SUCCESS;

	}


	public String getList() {
		return list;
	}


	public void setList(String list) {
		this.list = list;
	}
	
	

}
